home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / OrgPlus 7 SBE / ORGPL.CAB / profilePage.js < prev    next >
Encoding:
Text File  |  2007-05-15  |  9.3 KB  |  299 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: profilePage.js                               *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10. window.onload = doInit;
  11.  
  12. function Initialize()
  13. {
  14.   var width = parseInt(document.body.clientWidth);
  15.   var col = parseInt(width) / 3;
  16.   ListObject = new ListCtrl(document.body);
  17.   ListObject.AddColumn("<b>Field</b>");
  18.   ListObject.AddColumn("<b>Value</b>");
  19.   ListObject.Columns[0].SetWidth( col );
  20.   ListObject.Columns[1].SetWidth( width - col );
  21.   ListObject.HighlightColor = "#CCCCFF";
  22. }
  23.  
  24. function doInit()
  25. {
  26.   if( typeof(ListObject) == 'undefined' || ListObject == null )
  27.     Initialize();
  28.   
  29.   var obj = parent.hcMain
  30.   if ( typeof (obj) == "object" && typeof (obj.onNavigatePageInit) != "undefined" )
  31.     obj.onNavigatePageInit()
  32. }
  33.  
  34. function clearPage()
  35. {
  36.   ListObject.ClearTable();
  37.   ListObject.RemoveAll();
  38. }
  39.  
  40. function LoadOldProfile(group)
  41. {
  42.   if( typeof( group ) != "object" )
  43.     return;
  44.   
  45.   var ancObjs = group.getElementsByTagName("a")
  46.   for (i = 0; i < ancObjs.length; i++)
  47.   {
  48.     if( ancObjs(i).name != "Profile")
  49.       continue;
  50.  
  51.     var paramObjs = ancObjs(i).getElementsByTagName("param")
  52.     for (j = 0; j < paramObjs.length; j++)
  53.     {
  54.       var obj = paramObjs(j)
  55.       var str = obj.name
  56.       if (typeof(str) != "undefined" )
  57.       {
  58.         var strValue = ""
  59.         if ( typeof (obj.value) != "undefined" )
  60.           strValue = obj.value
  61.  
  62.         var newRow = null;
  63.         newRow = new Array( new ListCtlCell(str, 1), new ListCtlCell(strValue, 1) );
  64.         ListObject.Add( newRow );
  65.       }
  66.     }
  67.     break;
  68.   }
  69. };
  70.  
  71. function GetCurrentProfile()
  72. {
  73.   var ProfileData = parent.hcMain.getProfilesObj();
  74.   for( var iIndex = 0; iIndex < ProfileData.children.length; iIndex++ )
  75.   {
  76.     var oProfile = ProfileData.children[iIndex];
  77.     
  78.     if( typeof(oProfile.IsDefault) != "undefined" &&
  79.        ( oProfile.IsDefault == "true" || oProfile.IsDefault == true ) )
  80.       return oProfile;
  81.   };
  82. }
  83.  
  84. function fillPage(group)
  85. {
  86.   if( typeof(ListObject) == "undefined" || !ListObject )
  87.     Initialize();
  88.     
  89.   clearPage()
  90.   
  91.   if( !parent.hcPersons || !group )
  92.     return;
  93.   
  94.   var oProfile = GetCurrentProfile();
  95.   
  96.   if( typeof( oProfile.type ) != 'undefined' && parseInt( oProfile.type ) == 2 && g_gIEVer == 60 )
  97.   {
  98.     ShowHTMLProfile( oProfile, group );
  99.     return;
  100.   }
  101.   
  102.   var oData = parent.hcPersons.document.all[ group.id ];
  103.   
  104.   if( oData == null ) return;
  105.   if( typeof( oProfile.type ) != 'undefined' && parseInt( oProfile.type ) == 2 && g_gIEVer < 60 )
  106.     LoadOldProfile(group);
  107.   else
  108.   {
  109.     if( typeof( oProfile.ShowGrid) == 'undefined' || oProfile.ShowGrid == 1 || oProfile.ShowGrid == "1" )
  110.       ListObject.ShowGrid( true );
  111.     else
  112.       ListObject.ShowGrid( false );
  113.     
  114.     for( var i = 0; i < oProfile.children.length; ++i )
  115.     {
  116.       var oParam = oProfile.children[i];
  117.       
  118.       if( oParam.tagName != "PARAM" )
  119.         continue;
  120.       
  121.       var leftText = oParam.Name;
  122.       
  123.       if( typeof( oParam.LeftWordWrap ) != 'undefined' && (oParam.LeftWordWrap == 0 || oParam.LeftWordWrap == "0") )
  124.         leftText = "<NOBR>" + leftText + "</NOBR>";
  125.       
  126.       if( typeof( oParam.LeftStyle ) != 'undefined' )
  127.         leftText = oParam.LeftStyle + leftText + "</font>";
  128.  
  129.       var rightText;
  130.       if( typeof( oParam.FieldId ) != 'undefined' )
  131.       {
  132.         groupValue = null;
  133.         for( var fi = 0; fi < oData.children.length; ++fi )
  134.           if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == oParam.FieldId )
  135.           {
  136.             groupValue = oData.children[fi];
  137.             break;
  138.           };
  139.         
  140.         var LeftIcon = "";
  141.         var RightIcon = "";
  142.         
  143.         if( oParam.LeftIcon )
  144.         {
  145.           if( typeof( parseInt(oParam.LeftIcon) ) != 'undefined' )
  146.           {
  147.             var iconFldID = parseInt(oParam.LeftIcon);
  148.             var iconFld = null;
  149.             
  150.             for( var fi = 0; fi < oData.children.length; ++fi )
  151.               if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == iconFldID )
  152.               {
  153.                 iconFld = oData.children[fi];
  154.                 break;
  155.               };
  156.             LeftIcon = iconFld.name;
  157.           }
  158.           else
  159.           {
  160.             LeftIcon = oParam.LeftIcon;
  161.           }
  162.         }
  163.         
  164.         if( oParam.RightIcon )
  165.         {
  166.           if( typeof( parseInt(oParam.RightIcon) ) != 'undefined' )
  167.           {
  168.             var iconFldID = parseInt(oParam.RightIcon);
  169.             var iconFld = null;
  170.             
  171.             for( var fi = 0; fi < oData.children.length; ++fi )
  172.               if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == iconFldID )
  173.               {
  174.                 iconFld = oData.children[fi];
  175.                 break;
  176.               };
  177.             RightIcon = iconFld.name;
  178.           }
  179.           else
  180.           {
  181.             RightIcon = oParam.RightIcon;
  182.           }
  183.         }
  184.         
  185.         rightText = groupValue.name;
  186.         if( typeof( oParam.IsPicture ) != 'undefined' && oParam.IsPicture == 1 && rightText != "" )
  187.           rightText = "<img src=\"" + rightText + "\">";
  188.         
  189.         if( typeof( oParam.IsLink ) != 'undefined' && oParam.IsLink == 1 )
  190.         {
  191.           var strURL = groupValue.value;
  192.           if( typeof( strURL ) == 'undefined' )
  193.             strURL = groupValue.name;
  194.           
  195.           if( strURL.search('@') > 0 )
  196.             strURL = "mailto:" + strURL;
  197.           
  198.          strURL = strURL.replace( /\\/g, "\\\\" );
  199.          rightText = "<a href='javascript:void(0)' onclick=\"window.open('" + strURL + "')\">" + rightText + "</a>";
  200.         }
  201.  
  202.         if( LeftIcon && LeftIcon != "" )
  203.           rightText = "<img src=" + LeftIcon + " /> " + rightText;
  204.         if( RightIcon && RightIcon != "" )
  205.           rightText = rightText + " <img src=" + LeftIcon + " />";
  206.       }
  207.       else
  208.       {
  209.         if( typeof( oParam.RightText ) == 'undefined' )
  210.           continue;
  211.         
  212.         rightText = oParam.RightText;
  213.  
  214.         if( LeftIcon && LeftIcon != "" )
  215.           rightText = "<img src=" + LeftIcon + " /> " + rightText;
  216.         if( RightIcon && RightIcon != "" )
  217.           rightText = rightText + " <img src=" + LeftIcon + " />";
  218.       };
  219.       
  220.       
  221.       if( typeof( oParam.RightWordWrap ) != 'undefined' && (oParam.RightWordWrap == 0 || oParam.RightWordWrap == "0") )
  222.         rightText = "<NOBR>" + rightText + "</NOBR>";
  223.       
  224.       if( typeof( oParam.RightStyle ) != 'undefined' )
  225.         rightText = oParam.RightStyle + rightText + "</font>";
  226.  
  227.       var newRow = null;
  228.       if( typeof( oParam.Merged ) == 'undefined' || (oParam.Merged != true && oParam.Merged != "true" ) )
  229.         newRow = new Array( new ListCtlCell(leftText, 1), new ListCtlCell(rightText, 1) );
  230.       else
  231.         newRow = new Array( new ListCtlCell(rightText, 2) );
  232.         
  233.       ListObject.Add( newRow );
  234.     };
  235.   };
  236.  
  237.   if( typeof(ListObject.table) == 'undefined' || ListObject.table == null)
  238.     ListObject.Create(document.body);
  239.   else
  240.     ListObject.Show();
  241. }
  242.  
  243. var g_oSelectedGroupID = null;
  244. function ShowHTMLProfile( p_oProfile, p_oGroup )
  245. {
  246.   if( typeof( p_oGroup ) != "object" )
  247.     return;
  248.   if( typeof( p_oProfile.url ) == 'undefined' )
  249.     return;
  250.   
  251.   var iFrame = window.frames.hcHTMLProfile;
  252.   if( iFrame == null )
  253.   {
  254.     g_oSelectedGroupID = p_oGroup.id;
  255.     var frm = document.createElement( "<iframe onreadystatechange='PrepareHtml(this.readyState)' src='" + p_oProfile.url + "' name=\"hcHTMLProfile\" width=0 scrolling='no' border='0' frameborder='0' noresize topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'></iframe>");
  256.     document.body.appendChild( frm );
  257.   }
  258. }
  259.  
  260. function PrepareHtml( p_rs )
  261. {
  262.   if( p_rs != "complete" && g_oSelectedGroupID != null )
  263.     return;
  264.     
  265.   var oData = parent.hcPersons.document.all[ g_oSelectedGroupID ];
  266.   var FieldDefs   = parent.hcMain.getFieldsObj();
  267.   if( FieldDefs == null || oData == null ) return;
  268.   var iFrame = window.frames.hcHTMLProfile;
  269.   var  html = iFrame.document.body.innerHTML;
  270.   
  271.   for( var i = 0; i < FieldDefs.children.length; ++i )
  272.   {
  273.     var templateName = "\\[@" + FieldDefs.children[i].name + "@\\]";
  274.     for( var fi = 0; fi < oData.children.length; ++fi )
  275.       if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == FieldDefs.children[i].id )
  276.       {
  277.         groupValue = oData.children[fi];
  278.         break;
  279.       };
  280.  
  281.     html = html.replace( new RegExp( templateName, "g"), groupValue.name );
  282.   }
  283.   document.body.innerHTML = html;
  284.   
  285.   var oImagesCollection = document.body.getElementsByTagName("IMG");
  286.   if( typeof(oImagesCollection) == 'undefined' || oImagesCollection == null )
  287.     return;
  288.   
  289.   for( var i = 0; i < oImagesCollection.length; ++i )
  290.   {
  291.     oImagesCollection[i].onerror = ImageHider;
  292.   }
  293. }
  294.  
  295. function ImageHider()
  296. {
  297.   event.srcElement.style.visibility = "hidden";
  298. };
  299.